<?php
/**
 * 图片上传API
 * 2015年6月17日09:47:49
 * AUTHOR：Guangpeng Chen
 */
include '/var/www/html/new/d/class/Uploader.class.php';
if (!isset($_POST['callback'])) exit;
$callback = $_POST['callback'];
if (!$_SESSION['memberID']) {
    $json = '{"status":"fail","msg":"您还未登录或登录超时"}';
    echo '<script>window.parent.' . $callback . '('.$json.');</script>';
    exit;
}
//print_r($_FILES);exit;
$dirname = !empty($_POST['dirname']) ? trim($_POST['dirname']) : $_SESSION['account'];
$config = array(
    'simpleFolder'  => true,
    "savePath"      => "/databak/images/{$dirname}",
    "maxSize"       => 2048, //单位KB
    "allowFiles"    => array(".gif", ".png", ".jpg", ".jpeg", ".bmp"),
);
if (count($_FILES)==1) {
    $up = new Uploader('img_upload_file_input', $config);
    $info = $up->getFileInfo();
    if ($info['state']=='SUCCESS') {
        $json = '{"status":"ok", "src":"http://images.12301.cc/'.$dirname.'/'.$info['name'].'"}';
    } else {
        $json = '{"status":"fail"}';
    }
    echo '<script>window.parent.' . $callback . '('.$json.');</script>';
}
else {
    foreach($_FILES as $key=>$file){
        $up = new Uploader($key, $config);
        $info = $up->getFileInfo();
    }
    echo '<script>window.parent.' . $callback . '('.$json.');</script>';

}